package com.huike.web.controller.report;


import com.huike.common.core.domain.entity.SysUser;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.utils.ServletUtils;
import com.huike.framework.web.service.TokenService;
import com.huike.report.domain.vo.IndexBaseInfoVO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;

    @Autowired
    private TokenService tokenService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 查询  线索数量，商机数量，合同数量，成交的金额
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        HashMap<String, Object> map = new HashMap<>();
        Map<String, Object> resultMap = reportService.getTodayInfo(user,date,map);
        System.out.println(resultMap);
        return AjaxResult.success("操作成功", resultMap);
    }

    @GetMapping("/getTodoInfo")
    public Object getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                              @RequestParam("endCreateTime") String endCreateTime) {

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        Map<String, Object> resultMap = reportService.getTodoInfo(beginCreateTime, endCreateTime, user);
        return AjaxResult.success("操作成功", resultMap);
    }

    @GetMapping("/businessChangeStatistics")
    public Object businessChangeStatistics() {
        return null;
    }

    @GetMapping("/salesStatistic")
    public Object salesStatistic() {
        return null;
    }

    //private static CountDownLatch countDownLatch = new CountDownLatch(3);
    //private static int a=0;

//    public static void main(String[] args) {
//        for (int i = 0; i < 3; i++) {
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    a++;
//                    System.out.println(System.currentTimeMillis());
//                    countDownLatch.countDown();
//                }
//            }).start();
//        }
//        try {
//            countDownLatch.await();
//            System.out.println(a);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//    }
}